﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Fc
{
    public partial class 产品入库 : System.Web.UI.Page
    {
        protected string GetSCX()
        {
            if (this.RadioButton1.Checked) return "1号线";
            else if (this.RadioButton2.Checked) return "2号线";
            else return "";
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            int BillID = 0;
            int did;
            if (!this.IsPostBack)
            {

                if ((object)Session["OperatorDID"] != null)
                {
                    did = (int)Session["OperatorDID"];
                    if (did != 0)
                    {
                        this.FenChang.Text = did.ToString();
                        this.FenChang.Enabled = false;
                        if (did == 1)
                        {
                            this.ChanPin.Text = "2";
                            this.ChanPin.Enabled = false;
                        }
                        else if (did == 5)
                        {
                            this.ChanPin.Text = "1";
                            this.ChanPin.Enabled = false;
                            this.Panel7.Visible = true;
                            this.RadioButton1.Checked = true;

                        }
                    }
                }
                else
                {
                    did = 0;
                }
                this.Label_ZhiBiao.Text = (String)Session["OperatorName"];
                if (Request.QueryString["ID"] != null)
                {
                    int.TryParse(Request.QueryString["ID"], out BillID);
                }
                if (BillID > 0)
                {
                    this.YuanLiaoGongHuo.DataBind();
                    this.ChanPinList.DataTextField = "f1";
                    this.ChanPinList.DataValueField = "f2";
                    this.ChanPinList.DataSource = this.SqlDataSource2;
                    this.SqlDataSource2.SelectCommand = "select RTRIM(捆号)+''''+CAST(原料供货ID as varchar)+''''+RTRIM(炉号)+''''+CAST(重量 as varchar)+''''+CAST(长度 as varchar)+''''+CAST(支数 as varchar) as f1,'' as f2 from 产品库存 where 入库单ID=" + BillID;
                    this.ChanPinList.DataBind();

                    SqlConnection Conn = new SqlConnection();
                    Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                    Conn.Open();
                    SqlCommand Cmd = new SqlCommand();
                    Cmd.Connection = Conn;

                    Cmd.CommandText = "select * from [产品入库单] where [ID]=" + BillID;
                    Cmd.CommandType = CommandType.Text;
                    SqlDataReader Reader = Cmd.ExecuteReader();
                    if (Reader.Read())
                    {
                        this.FenChang.Text = ((int)Reader["生产单位ID"]).ToString();
                        this.ChanPin.Text = ((int)Reader["产品类别ID"]).ToString();
                        this.RiQi.Text = ((DateTime)Reader["日期"]).ToLongDateString();
                        this.KuQu.Text = ((byte)Reader["库区"]).ToString();
                        this.XuHao.Text = ((string)Reader["序号"]).Trim();
                        this.LuHao.Text = ((string)Reader["炉号"]).Trim();
                        this.YuanLiaoGongHuo.Text = ((int)Reader["供货单位ID"]).ToString();
                        this.Label_ZC.Text = ((double)Reader["总长度"]).ToString(".00");
                        this.Label_ZZ.Text = ((double)Reader["总重量"]).ToString(".0");
                        this.Label_ZJ.Text = ((int)Reader["总件数"]).ToString();
                        this.Label_ZZhi.Text = ((int)Reader["总支数"]).ToString();
                        this.Label_ZhiBiao.Text = ((string)Reader["制表人"]).Trim();
                        this.Label_ZhiBiao.Text = ((string)Reader["制表人"]).Trim();
                        this.Label_PanDing.Text = ((string)Reader["质检员"]).Trim();
                        this.Label_JieLun.Text = ((string)Reader["判定结论"]);
                        this.Label_BeiZhu.Text = ((string)Reader["备注"]).Trim();
                        this.BeiZhu.Text = ((string)Reader["备注"]).Trim();

                        if ((int)Reader["生产线"]==1)
                        {
                            this.RadioButton1.Checked = true;
                            this.RadioButton2.Checked = false;
                        }
                        else if ((int)Reader["生产线"] == 2)
                        {
                            this.RadioButton1.Checked = false;
                            this.RadioButton2.Checked = true;
                        }

                        this.Button_Set_Click(null, null);
                        this.Button_Save.Enabled = false;
                        this.ViewState["BillID"] = BillID;
                        if ((bool)Reader["是否合格"])
                        {
                            this.Button_Save.Visible = false;
                            this.Button_Change.Visible = false;
                            this.Panel2.Visible = false;
                            this.Panel3.Visible = false;
                            this.Panel6.Visible = true;
                            this.Label1.Text = "查看";
                        }
                        this.Message.Text = "·加载成功";
                    }
                    Reader.Close();

                    Conn.Close();
                    Reader.Dispose();
                    Cmd.Dispose();
                    Conn.Dispose();

                }
                else
                {
                    InitSerial();
                }
            }

            DateTime d;
            if (!DateTime.TryParse(this.RiQi.Text, out d))
            {
                if (DateTime.Now.Hour > 12)
                {
                    this.RiQi.Text = DateTime.Today.ToString("yyyy年M月d日");
                }
                else
                {
                    RiQi.Text = DateTime.Today.AddDays(-1).ToString("yyyy年M月d日");
                }

            }

        }
        private void InitSerial()
        {
            if (this.ViewState["BillID"] == null)
            {
                int did;
                if ((object)Session["OperatorDID"] != null)
                {
                    did = (int)Session["OperatorDID"];
                }
                else
                {
                    did = 0;
                }

                int scx = 0;
                if (this.RadioButton1.Checked) scx = 1;
                else if (this.RadioButton2.Checked) scx = 2;

                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                Conn.Open();
                SqlCommand Cmd = new SqlCommand();
                Cmd.Connection = Conn;

                Cmd.CommandText = "select top 1 序号 from [产品入库单] where [生产单位ID]=" 
                    + did + " and 产品类别ID=" + this.ChanPin.Text + " and 生产线="
                    + scx + " order by 录入日期 desc";
                Cmd.CommandType = CommandType.Text;
                SqlDataReader Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    int xh = 0;
                    int.TryParse((string)Reader[0], out xh);
                    this.XuHao.Text = (++xh).ToString();
                }
                else
                {
                    this.XuHao.Text = "1";
                }
                Reader.Close();

                Conn.Close();
                Reader.Dispose();
                Cmd.Dispose();
                Conn.Dispose();
            }
        }
        protected void Button_Add_Click(object sender, EventArgs e)
        {

            double kunzhongliang = 0, kunchangdu = 0;
            int zhishu = 0,i;
            int zongjian = 0, zongzhi = 0;
            double zongzhong = 0, zongchang = 0;
            int kunhao = 0;
            if(!int.TryParse(this.ZhiShu.Text,out zhishu))
            {
                this.Message.Text="·支数输入有误";
                return;
            }
            else if (zhishu < 1 || zhishu > 50)
            {
                this.Message.Text = "·支数输入有误";
                return;
            }

            if (!double.TryParse(this.KunZhong.Text, out kunzhongliang))
            {
                this.Message.Text="·捆重量输入有误";
                return;
            }
            else if (kunzhongliang < 1 || kunzhongliang > 3000)
            {
                this.Message.Text = "·捆重量输入有误";
                return;
            }

            if (!double.TryParse(this.KunChang.Text, out kunchangdu))
            {
                this.Message.Text = "·捆长度输入有误";
                return;
            }
            else if (kunchangdu < 1 || kunchangdu > 500)
            {
                this.Message.Text = "·捆长度输入有误";
                return;
            }
            
            if(this.LuHao.Text.IndexOf('\'')>-1)
            {
                this.Message.Text="·炉号包含无效字符";
            }

            if(this.LuHao.Text.Length>10)
            {
                this.Message.Text="·炉号太长";
                return;
            }

            if(this.KunHao.Text.Length>4)
            {
                this.Message.Text = "·捆编号太大";
                return;
            }

            if (!int.TryParse(this.KunHao.Text, out kunhao))
            {
                this.Message.Text = "·捆编号输入有误";
                return;
            }

            int kunhao0=0;
            string[] ta;
            for(i=0;i<this.ChanPinList.Items.Count;i++)
            {
                ta = this.ChanPinList.Items[i].Text.Split("'".ToCharArray())[0].Split("-".ToCharArray());

                if (ta.Length > 1)
                {
                    kunhao0=int.Parse(ta[1]);
                }
                else
                {
                    kunhao0 = int.Parse(ta[0]);
                }
                //Response.Write(kunhao0 + " " + kunhao + "<br>");
                if (kunhao0 >= kunhao)
                {
                    break;
                }
            }

            if (i == this.ChanPinList.Items.Count || kunhao0 > kunhao)
            {
                if (this.ChanPinList.Items.Count >= 60)
                {
                    this.Message.Text = "·录入失败，最多最能录入60捆";
                    return;
                }
                ListItem li = new ListItem();
                li.Text = this.KunHaoQZ.Text + kunhao
                    + "'" + this.YuanLiaoGongHuo.Text
                    + "'" + this.LuHao.Text
                    + "'" + this.KunZhong.Text
                    + "'" + this.KunChang.Text
                    + "'" + this.ZhiShu.Text;
                li.Value = "";

                if (i == this.ChanPinList.Items.Count)
                {
                    this.ChanPinList.Items.Add(li);
                }
                else
                {
                    this.ChanPinList.Items.Insert(i, li);
                }

                int.TryParse(this.Label_ZJ.Text, out zongjian);
                int.TryParse(this.Label_ZZhi.Text, out zongzhi);
                double.TryParse(this.Label_ZZ.Text, out zongzhong);
                double.TryParse(this.Label_ZC.Text, out zongchang);

                this.Label_ZZ.Text = (zongzhong + kunzhongliang).ToString(".0");
                this.Label_ZC.Text = (zongchang + kunchangdu).ToString(".00");
                this.Label_ZJ.Text = (zongjian + 1).ToString();
                this.Label_ZZhi.Text = (zongzhi + zhishu).ToString();
            }
            else
            {
                double oldkunzhongliang, oldkunchangdu;
                int oldzhishu;
                string luhao0;
                string[] item = this.ChanPinList.Items[i].Text.Split("'".ToCharArray());
                luhao0=item[2];
                double.TryParse(item[3], out oldkunzhongliang);
                double.TryParse(item[4], out oldkunchangdu);
                int.TryParse(item[5], out oldzhishu);

                int.TryParse(this.Label_ZJ.Text, out zongjian);
                int.TryParse(this.Label_ZZhi.Text, out zongzhi);
                double.TryParse(this.Label_ZZ.Text, out zongzhong);
                double.TryParse(this.Label_ZC.Text, out zongchang);

                this.Label_ZZ.Text = (zongzhong - oldkunzhongliang + kunzhongliang).ToString();
                this.Label_ZC.Text = (zongchang - oldkunchangdu + kunchangdu).ToString();
                this.Label_ZZhi.Text = (zongzhi - oldzhishu + zhishu).ToString();

                this.ChanPinList.Items[i].Text = this.KunHao.Text
                    + "'" + this.YuanLiaoGongHuo.Text
                    + "'" + this.LuHao.Text
                    + "'" + this.KunZhong.Text
                    + "'" + this.KunChang.Text
                    + "'" + this.ZhiShu.Text;
                i++;
                for (; i < this.ChanPinList.Items.Count; i++)
                {
                    item = this.ChanPinList.Items[i].Text.Split("'".ToCharArray());
                    if (item[2] == luhao0)
                    {
                        item[2] = this.LuHao.Text;
                        item[1] = this.YuanLiaoGongHuo.Text;
                        this.ChanPinList.Items[i].Text = string.Join("'", item);
                    }
                    else
                    {
                        break;
                    }
                }
            }


            this.KunHao.Text = (kunhao + 1).ToString();

            this.Message.Text = "·捆录入成功";
            this.Button_Save.Enabled = true;
        }

        protected void Button_Change_Click(object sender, EventArgs e)
        {
            this.Panel2.Visible = true;
            this.Panel3.Visible = false;
            this.Button_Change.Visible = false;
        }

        protected void Button_Set_Click(object sender, EventArgs e)
        {
            if (this.ChanPin.Text == "1")
            {
                this.ZhiShu.Text = "19";
            }
            else
            {
                this.ZhiShu.Text = "7";
            }
            byte cunchuquyu;
            if (!byte.TryParse(this.KuQu.Text, out cunchuquyu))
            {
                this.Message.Text = "·存储区域需输入一个数字";
                return;
            }
            int xh;
            if (!int.TryParse(this.XuHao.Text, out xh))
            {
                this.Message.Text = "·入库序号需输入一个数字";
                return;
            }
            if (this.FenChang.Text == "5" && !this.RadioButton1.Checked && !this.RadioButton2.Checked)
            {
                this.Message.Text = "·请先选择生产线";
                return;
            }



            DateTime d1;
            if (!DateTime.TryParse(RiQi.Text, out d1))
            {
                this.Message.Text = "·入库序号需输入一个数字";
                return;
            }
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;

            Cmd.CommandText ="select 年度,月份 from 生产月设置 where 分厂=@fc and @d0>=起始日期 and @d0<=截止日期";
            Cmd.CommandText = Cmd.CommandText.Replace("@d0", "'" + d1.ToShortDateString() + "'");
            Cmd.CommandText = Cmd.CommandText.Replace("@fc", this.FenChang.Text);
            Cmd.CommandType = CommandType.Text;
            SqlDataReader Reader = Cmd.ExecuteReader();
            if (Reader.Read())
            {
                string t = ((int)Reader[0]).ToString();
                t = t.Substring(t.Length - 2);
                this.KunHaoQZ.Text = t;
                t = "0"+((int)Reader[1]).ToString();
                t = t.Substring(t.Length - 2);
                this.KunHaoQZ.Text +=t+"-";
            }
            else
            {
                this.KunHaoQZ.Text=d1.ToString("yyMM")+"-";
            }
            Reader.Close();

            Conn.Close();
            Reader.Dispose();
            Cmd.Dispose();
            Conn.Dispose();
            string[] item;
            string[] ta;
            string kunhao="";
            for (int i=0; i < this.ChanPinList.Items.Count; i++)
            {
                item = this.ChanPinList.Items[i].Text.Split("'".ToCharArray());

                ta = item[0].Split("-".ToCharArray()) ;

                if (ta.Length > 1)
                {
                    kunhao = ta[1];
                }
                else
                {
                    kunhao = ta[0];
                }
                item[0] = this.KunHaoQZ.Text + kunhao;
                this.ChanPinList.Items[i].Text = string.Join("'", item);
 
            }

            this.Label_BeiZhu.Text = this.BeiZhu.Text;

            this.Panel2.Visible = false;
            this.Panel3.Visible = true;
            this.Button_Change.Visible = true;
            this.Button_Save.Enabled = true;
            this.Message.Text = "·设置成功";
        }

        protected void Button_Save_Click(object sender, EventArgs e)
        {
            if (this.Label_ZJ.Text == "0")
            {
                this.Message.Text = "·您至少要录入一捆产品";
                return;
            }

            byte cunchuquyu;
            if (!byte.TryParse(this.KuQu.Text, out cunchuquyu))
            {
                this.Message.Text = "·存储区域需输入一个数字";
                Button_Change_Click(null, null);
                return;
            }
            int xh;
            if (!int.TryParse(this.XuHao.Text, out xh))
            {
                this.Message.Text = "·入库序号需输入一个数字";
                Button_Change_Click(null, null);
                return;
            }
            string op = (string)this.Session["OperatorName"];
            if (op == null)
            {
                op = "未知用户";
            }
            int scx = 0;
            if (this.RadioButton1.Checked) scx = 1;
            if (this.RadioButton2.Checked) scx = 2;

            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlTransaction Tran = Conn.BeginTransaction();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.Transaction = Tran;
            try
            {
                Cmd.CommandText = "ChanPin_In_Bill";
                Cmd.CommandType = CommandType.StoredProcedure;
                if (this.ViewState["BillID"] == null)
                {
                    this.ViewState["BillID"] = -1;
                }
                Cmd.Parameters.Add(new SqlParameter("@序号", SqlDbType.Char, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.XuHao.Text));
                Cmd.Parameters.Add(new SqlParameter("@产品类别ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(this.ChanPin.Text)));
                Cmd.Parameters.Add(new SqlParameter("@供货单位ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(this.YuanLiaoGongHuo.Text)));
                Cmd.Parameters.Add(new SqlParameter("@生产单位ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(this.FenChang.Text)));
                Cmd.Parameters.Add(new SqlParameter("@生产线", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, scx));
                Cmd.Parameters.Add(new SqlParameter("@炉号", SqlDbType.NChar, 40, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.LuHao.Text));
                Cmd.Parameters.Add(new SqlParameter("@日期", SqlDbType.Date, 3, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, DateTime.Parse(RiQi.Text)));
                Cmd.Parameters.Add(new SqlParameter("@库区", SqlDbType.TinyInt, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, cunchuquyu));

                Cmd.Parameters.Add(new SqlParameter("@总件数", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(this.Label_ZJ.Text)));
                Cmd.Parameters.Add(new SqlParameter("@总支数", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(this.Label_ZZhi.Text)));
                Cmd.Parameters.Add(new SqlParameter("@总重量", SqlDbType.Float, 8, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, double.Parse(this.Label_ZZ.Text)));
                Cmd.Parameters.Add(new SqlParameter("@总长度", SqlDbType.Float, 8, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, double.Parse(this.Label_ZC.Text)));

                Cmd.Parameters.Add(new SqlParameter("@制表人", SqlDbType.NChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, op));
                Cmd.Parameters.Add(new SqlParameter("@备注", SqlDbType.NChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.BeiZhu.Text));

                Cmd.Parameters.Add(new SqlParameter("@BillID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.ViewState["BillID"]));
                Cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4, ParameterDirection.Output, true, 0, 0, "", DataRowVersion.Proposed, null));

                Cmd.ExecuteNonQuery();

                this.ViewState["BillID"] = (int)Cmd.Parameters["@ID"].Value;
                int BillID = (int)this.ViewState["BillID"];
                if (BillID > 0)
                {
                    Cmd.CommandText = "ChanPin_In";
                    Cmd.Parameters.Clear();
                    Cmd.Parameters.Add(new SqlParameter("@入库单ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, BillID));
                    Cmd.Parameters.Add(new SqlParameter("@产品类别ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(this.ChanPin.Text)));
                    Cmd.Parameters.Add(new SqlParameter("@生产单位ID", SqlDbType.TinyInt, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, byte.Parse(this.FenChang.Text)));
                    Cmd.Parameters.Add(new SqlParameter("@入库日期", SqlDbType.SmallDateTime, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, DateTime.Parse(RiQi.Text)));
                    Cmd.Parameters.Add(new SqlParameter("@库区", SqlDbType.TinyInt, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, cunchuquyu));

                    
                    Cmd.Parameters.Add(new SqlParameter("@原料供货ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(this.YuanLiaoGongHuo.Text)));
                    Cmd.Parameters.Add(new SqlParameter("@炉号", SqlDbType.Char, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.LuHao.Text));
                    Cmd.Parameters.Add(new SqlParameter("@捆号", SqlDbType.Char, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, ""));
                    Cmd.Parameters.Add(new SqlParameter("@重量", SqlDbType.Float, 8, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 0));
                    Cmd.Parameters.Add(new SqlParameter("@长度", SqlDbType.Float, 8, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 0));
                    Cmd.Parameters.Add(new SqlParameter("@支数", SqlDbType.TinyInt, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 0));
                    

                    int kunhao=0;
                    string[] ta;

                    string[] item;
                    for (int i = 0; i < this.ChanPinList.Items.Count; i++)
                    {
                        item = this.ChanPinList.Items[i].Text.Split("'".ToCharArray());

                        ta = item[0].Split("-".ToCharArray());

                        if (ta.Length > 1)
                        {
                            kunhao = int.Parse(ta[1]);
                        }
                        else
                        {
                            kunhao = int.Parse(ta[0]);
                        }

                        Cmd.Parameters["@原料供货ID"].Value = int.Parse(item[1]);
                        Cmd.Parameters["@炉号"].Value = item[2];
                        Cmd.Parameters["@捆号"].Value = this.KunHaoQZ.Text + kunhao;
                        Cmd.Parameters["@重量"].Value = double.Parse(item[3]);
                        Cmd.Parameters["@长度"].Value = double.Parse(item[4]);
                        Cmd.Parameters["@支数"].Value = byte.Parse(item[5]);
                        Cmd.ExecuteNonQuery();
                    }
                }

                Tran.Commit();
            }
            catch (Exception err)
            {
                Tran.Rollback();
                this.Message.Text = err.Message;
            }
            Cmd.Dispose();
            Tran.Dispose();
            Conn.Close();
            Conn.Dispose();

            this.Panel2.Visible = false;
            this.Panel3.Visible = true;
            this.Button_Change.Visible = true;
            this.Button_Save.Enabled = false;
            this.Message.Text = "·保存成功";
        }

        protected void Button_Del_Click(object sender, EventArgs e)
        {
            int kunhao = 0;
            int kunhao0=0;
            string[] ta;

            if (!int.TryParse(this.KunHao.Text, out kunhao))
            {
                this.Message.Text = "·捆编号输入有误";
                return;
            }



            for (int i = 0; i < this.ChanPinList.Items.Count; i++)
            {
                ta = this.ChanPinList.Items[i].Text.Split("'".ToCharArray())[0].Split("-".ToCharArray());

                if (ta.Length > 1)
                {
                    kunhao0 = int.Parse(ta[1]);
                }
                else
                {
                    kunhao0 = int.Parse(ta[0]);
                }

                if (kunhao == kunhao0)
                {
                    string[] item = this.ChanPinList.Items[i].Text.Split("'".ToCharArray());

                    double kunzhongliang=0, kunchangdu=0;
                    int zhishu = 0;
                    int zongjian = 0,zongzhi=0;
                    double zongzhong = 0, zongchang = 0;

                    double.TryParse(item[3], out kunzhongliang);
                    double.TryParse(item[4], out kunchangdu);
                    int.TryParse(item[5], out zhishu);

                    int.TryParse(this.Label_ZJ.Text, out zongjian);
                    int.TryParse(this.Label_ZZhi.Text, out zongzhi);
                    double.TryParse(this.Label_ZZ.Text, out zongzhong);
                    double.TryParse(this.Label_ZC.Text, out zongchang);

                    this.Label_ZZ.Text = (zongzhong - kunzhongliang).ToString();
                    this.Label_ZC.Text = (zongchang - kunchangdu).ToString();
                    this.Label_ZJ.Text = (zongjian -1).ToString();
                    this.Label_ZZhi.Text = (zongzhi - zhishu).ToString();

                    this.ChanPinList.Items.RemoveAt(i);
                    this.Message.Text = "·捆删除成功";
                    return;
                }
            }
            this.Message.Text = "·捆删除失败，该捆号并未录入";
        }

        protected void ChanPin_SelectedIndexChanged(object sender, EventArgs e)
        {
            InitSerial();
        }

        protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            InitSerial();
        }

        protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            InitSerial();
        }

    }
}
